package com.example.abe.diandi.trends.fragment;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.example.BindView;
import com.example.abe.diandi.R;
import com.example.abe.diandi.base.BaseFragment;
import com.example.abe.diandi.trends.model.ImageTextModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by abe on 17/1/12.
 */
public class TrendsEditTextFragment extends BaseFragment implements ITrendEditor{

    @BindView(R.id.frag_trends_edit_text_et_content)
    protected EditText mEtContent;

    @BindView(R.id.frag_trends_edit_text_tv_word_size)
    protected TextView mTvWords;

    private String mStrContent;

    public static TrendsEditTextFragment instance() {
        return new TrendsEditTextFragment();
    }

    @Override
    public int getLayoutID() {
        return R.layout.fragment_trends_edit_text;
    }

    @Override
    public void initData() {
    }

    @Override
    public void initView() {
        mEtContent.addTextChangedListener(mEtWatcher);
    }

    TextWatcher mEtWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mStrContent = mEtContent.getText().toString();
            mTvWords.setText(mStrContent.length()+"字");
        }
    };

    @Override
    public List<ImageTextModel> getImageTextModelList(){
        return new ArrayList<>();
    }

    @Override
    public String getTextContent(){
        return mStrContent;
    }
}
